/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package extension.game.zone;

import com.smartfoxserver.v2.entities.Room;
import com.smartfoxserver.v2.entities.User;
import com.smartfoxserver.v2.entities.data.ISFSObject;
import com.smartfoxserver.v2.extensions.BaseClientRequestHandler;
import extension.game.database.Database;
import extension.game.database.UserData;
import log.Debug;

/**
 *
 * @author daz
 */
public class BetMoneyInfoHandler extends BaseClientRequestHandler {
    
    @Override
    public void handleClientRequest(User user, ISFSObject params) {
        GameZoneExtension ext = (GameZoneExtension) getParentExtension();
        Response response = ext.getResponse();
        Database database = ext.getDatabase();
        String roomName = params.getUtfString("room_name");
        Room room = ext.getParentZone().getRoomByName(roomName);
        long betMoney = (Long) room.getProperty(Flag.BET_MONEY);
        Debug.d("room :" + roomName + " =>bet :" + betMoney);
        if (!Debug.isDebug) {
            UserData userData = database.getUserInfo(user.getName());
            if (userData.getMoney() < betMoney * 20) {
                response.sendNotEnough(user);
            } else {
                long moneyJoinMin = betMoney * 20;
                long moneyJoinMax = betMoney * 100;
                if (moneyJoinMax > userData.getMoney()) {
                    moneyJoinMax = userData.getMoney();
                }
                response.sendBetMoneyInfo(userData.getMoney(), moneyJoinMin, moneyJoinMax, roomName, user);
            }
        } else {
            long moneyJoinMin = betMoney * 20;
            long moneyJoinMax = betMoney * 100;
            response.sendBetMoneyInfo(10000, moneyJoinMin, moneyJoinMax, roomName, user);
        }
    }
}
